home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / basic / Prefs2000.lha / PrefsReader2000 / PrefsProcedures.ASC < prev    next >
Text File  |  1999-03-19  |  3KB  |  155 lines

  1.  
  2. ;
  3. ; The main procedures for Prefs2000, (C) Robert Hutchinson 1999!
  4. ; This is the guts of the program,.. Check the docs!
  5. ;
  6.  
  7. NEWTYPE .prefs
  8.   Info.s
  9. End NEWTYPE
  10.  
  11. Dim List Prefs.prefs(300)  ; make as big as you like, wont use the mem until you allocate entries
  12.  USEPATH Prefs()
  13.  
  14. BasePointer.w=0            ; Position in the list
  15.   BaseCount.w=0            ; Entries in the list
  16.  
  17. ;--- Function definitions
  18. ;
  19. ;
  20. Function.b ReadPrefs{PrefsFileLoc$}
  21.   SHARED Prefs()
  22.  
  23.   If ReadFile(0,PrefsFileLoc$)  ; Attempt read lock on specified file
  24.     FileInput 0
  25.  
  26.     ClearList Prefs()           ; Prepare linked list.
  27.     ResetList Prefs()
  28.  
  29.     While NOT Eof(0)
  30.       If AddItem(Prefs())       ; If there is space in our list (IE if not over 300), then add the entry
  31.         \Info=Edit$(500)        ; Grab values
  32.         BaseCount+1
  33.       Else
  34.         Nuked$=Edit$(500)       ; Just dump entries over the amount specifed in: DIM Prefs.prefs(300)
  35.       EndIf
  36.     Wend
  37.     CloseFile 0
  38.     Function Return True
  39.   Else
  40.     CloseFile 0
  41.     Function Return False
  42.   EndIf
  43.  
  44. End Function
  45.  
  46.  
  47. CaseSense Off  ;Make a searches non-case sensitive!
  48.  
  49. Function.s SearchPrefs{SearchString$}
  50.   SHARED Prefs()
  51.   SHARED BasePointer
  52.   BasePointer=0
  53.  
  54.   ;--- Prepare list
  55.   ;
  56.   ResetList Prefs()
  57.  
  58.     ;--- Our search algorithm
  59.     ;
  60.     While NextItem(Prefs())
  61.       BasePointer+1
  62.       If NoCont<>1                  ; If we havent found a match already
  63.         If Left$(\Info,1)<>Chr$(59) ; If not a semicolon (commented line)
  64.           If Instr(\Info,SearchString$)>0 ; Do we have a match??
  65.             For TMP=0 To Len(\Info)
  66.               If GotMatch<>1
  67.                 If Mid$(\Info,TMP,1)=Chr$(61) ; Do we have an equals symbol
  68.                   Match$=Mid$(\Info,TMP+2,500) ; get our value
  69.                   GotMatch=1
  70.                   NoCont=1
  71.                 EndIf
  72.               EndIf
  73.             Next
  74.             GotMatch=0
  75.           EndIf
  76.         EndIf
  77.       EndIf
  78.     Wend
  79.     NoCont=0
  80.  
  81.   Function Return Match$
  82.  
  83. End Function
  84.  
  85. Statement ReplaceEntry{SearchString$,Value$}
  86.   SHARED Prefs()
  87.   SHARED BasePointer
  88.   BasePointer=0
  89.  
  90.   ;--- Prepare list for parsing!
  91.   ;
  92.   ResetList Prefs()
  93.  
  94.     ;--- Our search algorithm
  95.     ;
  96.     While NextItem(Prefs())
  97.       BasePointer+1
  98.       If NoCont<>1                  ; If we havent found a match already
  99.         If Left$(\Info,1)<>Chr$(59) ; If not a semicolon (commented line)
  100.           If Instr(\Info,SearchString$)>0 ; Do we have a match??
  101.             For TMP=0 To Len(\Info)
  102.               If GotMatch<>1
  103.                 If Mid$(\Info,TMP,1)=Chr$(61) ; Do we have an equals symbol
  104.  
  105.                    Front$=Left$(\Info,TMP)
  106.                   NFront$=Front$+Chr$(32)+Value$
  107.  
  108.                     \Info=NFront$
  109.  
  110.                   GotMatch=1
  111.                   NoCont=1
  112.  
  113.                 EndIf
  114.               EndIf
  115.             Next
  116.             GotMatch=0
  117.           EndIf
  118.         EndIf
  119.       EndIf
  120.     Wend
  121.     NoCont=0
  122.  
  123. End Statement
  124.  
  125.  
  126. Function.b SavePrefs{PrefsFileLoc$}
  127.   SHARED Prefs()
  128.  
  129.   If WriteFile(0,PrefsFileLoc$)  ; Attempt write lock on specified file
  130.     FileOutput 0
  131.  
  132.     ResetList Prefs()
  133.  
  134.     While NextItem(Prefs())
  135.       NPrint \Info
  136.     Wend
  137.  
  138.     CloseFile 0
  139.     DefaultOutput
  140.     Function Return True
  141.   Else
  142.     CloseFile 0
  143.     DefaultOutput
  144.     Function Return False
  145.   EndIf
  146.  
  147. End Function
  148.  
  149.  
  150. Statement NukePrefs{}
  151.   SHARED Prefs()
  152.   ClearList Prefs()
  153. End Statement
  154.  
  155.